/**
 * Created by 51ibm on 2015/6/23.
 */

(function(root){

var currentidx;//当前在shadow中显示的图片下标
/**
 * 把下标为idx的图片显示到shadow
 * @idx 下标
 * @node 下表为idx的img的queryobject.
 * */
function extracted(idx,node) {
    $("#photo").attr({"src": "photo/" + (idx+1) + ".jpg"});
    if (node.hasClass("pt")) {
        $("#photo").removeClass("photols");
        $("#photo").addClass("photopt");
    } else {
        $("#photo").removeClass("photopt");
        $("#photo").addClass("photols");
    }
}

$(root).ready(function () {
    for (var i = 1; i <= 30; i++) {
        var node = $("<img src='photo/thumb/" + i + ".jpg'/>");
        $("body").append(node);
        //node.load(function () {
        node.on("load",function(){
                var node= $(this);
                var h =node.height();
                var w = node.width();
                console.log(h + ":" + w);
                if (h > w) {
                    node.addClass("pt");
                } else {
                    node.addClass("ls");
                }
            }
        );
    }
    $("img").not(".shadow img").click(function(){
        var idx=$("img").not(".shadow img").index(this);
        extracted(idx,$(this));
        $(".shadow").show();
        currentidx=idx;

    });
    $("#close").click(function(){
        $(".shadow").hide();
    });

    $("#prev").click(function(){
        currentidx=(currentidx+29)%30;
        extracted(currentidx,$("img").not(".shadow img").eq(currentidx));
    });
    $("#next").click(function(){
        currentidx=(currentidx+1)%30;
        extracted(currentidx,$("img").not(".shadow img").eq(currentidx));
    });

});

})(document);



